﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/Basic.Master" AutoEventWireup="true" CodeBehind="RoleList.aspx.cs" Inherits="PMS.UI.BD.RoleList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        $(function () {
            $("#tbList").datagrid({
                url: '/Logic/BD/RoleAjax.aspx?method=GetRoleList',
                loadMsg: '数据加载中请稍后……',
                //fitColumns: true,
                pagination: true,
                rownumbers: true,
                idField: "Id",      
                singleSelect: true,
                pageSize: 10,
                pageList: [10, 20, 30],
                columns: [[
                    {
                        field: 'ck', checkbox: true, width: 30
                    },
                    {
                        field: 'Name', title: '角色名称', sortable: true, align: "center", width: 200,
                        editor: {
                            type: "validatebox",
                            options: {
                                required: true
                            }
                        }

                    }, {
                        field: 'AddTime', title: '修改时间', align: "center", width: 240,

                        

                    }, {
                        field: 'Remark', title: '备注', align: "center", width: 600,
                        editor: {
                            type: "text"
                        }
                    }
                ]],
                singleSelect: true,
                pageSize: 20,
                pageList: [20, 50, 100],
                striped: true,
                onAfterEdit: function (rowIndex, rowData, changes) {
                    
                    if (editAction == "edit") {
                        com.ajax({
                            url: "/Logic/BD/RoleAjax.aspx?method=AddRole&&action=edit",
                            data: rowData,
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                            }
                        });
                    } else if (editAction == "add") {
                        
                        com.ajax({
                            url: "/Logic/BD/RoleAjax.aspx?method=AddRole&&action=add",
                            data: rowData,
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                            }
                        });
                    }
                    editRow = undefined;

                    
                }
                    
                
            })
        })
    </script>
    <script type="text/javascript">

        editRow = undefined;
        editAction = undefined;
        function funcAdd() {
            //添加时先判断是否有开启编辑的行，如果有则把开户编辑的那行结束编辑
            if (editRow != undefined) {

            }
            //添加时如果没有正在编辑的行，则在datagrid的第一行插入一行
            if (editRow == undefined) {
                $("#tbList").datagrid("insertRow", {
                    index: 0, // index start with 0
                    row: {

                    }
                });
                //将新插入的那一行开户编辑状态
                $("#tbList").datagrid("beginEdit", 0);
                
                //给当前编辑的行赋值
                editRow = 0;
                
                editAction = "add";
            }
        }
        function funcEdit() {

            var row = $('#tbList').datagrid('getSelected');
            if (row) {
                if (editRow != undefined) {
                }
                else {
                    var index = $("#tbList").datagrid('getRowIndex', row);
                    //   var index = row.Id;
                    $("#tbList").datagrid('beginEdit', index);
                    editAction = "edit";
                    editRow = index;
                }
            }
            else {
                com.message("information", "请选中一行");
            }
        }
        function funcSave() {
            $('#tbList').datagrid('endEdit', editRow);
            
        }
        function funcRemove() {
            $.messager.confirm('确认对话框', '您确定删除该权限吗？', function (r) {
                if (r) {
                    var rowData = $("#tbList").datagrid("getSelected");
                    if (rowData) {
                        com.ajax({
                            url: '/Logic/BD/RoleAjax.aspx?method=DelRole',
                            data: { Id: rowData.Id },
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); })

                            }

                        });
                    }
                }
            });
        }
        function funcAssign() {
            var row = $('#tbList').datagrid('getSelected');
            if (row) {

                $.extend(com.dialogObj, { title: "分配权限", width: 500, height: 300, href: "/UI/BD/AssignPermWindow.aspx" });
                $("#assignPermDiv").dialog(
                   com.dialogObj
                );
                $(top.document).find("#hidId").val(row.Id);
                console.log($(top.document).find("#hidId").val());
            }
            else {
                com.message("information", "请选中一行");
            }

        }

        function funAssignBtn() {
            var row = $('#tbList').datagrid('getSelected');
            if (row) {
                $.extend(com.dialogObj, { title: "分配按钮权限", width: 600, height: 400, href: "/UI/BD/AssignPermBtnWindow.aspx" });
                $("#assignPermDiv").dialog(com.dialogObj
                    );
                $(top.document).find("#hidId").val(row.Id);
               // console.log($(top.document).find("#hidId").val());
            }
            else {
                com.message("information", "请选中一行");
            }
        }

        function funcAssignPer() {
            var row = $('#tbList').datagrid('getSelected');
            if (row) {
                top.wrapper.addTab("分配权限", "/UI/BD/AssignAllPerm.aspx?action=edit&type=role&Id="+row.Id);
            }
            else {
                com.message("information", "请选中一行");
            }
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <div style="height: 100%;">

        <table id="tbList" data-options="fit:true"></table>
    </div>

    <div id="assignPermDiv">
      
    </div>



</asp:Content>
